import csv
import py2neo
from py2neo import Graph,Node,Relationship,NodeMatcher

# 链接数据库
g = Graph('http://localhost:7474',user='neo4j',password='xf123456789')
with open('./databases/Relationship.csv','r',encoding='utf-8') as f:
    reader = csv.reader(f)
    for item in reader:
        # 第一行是属性不需要
        if reader.line_num == 1:
            continue
        # 测试文件能不能输出
        # print("当前行数：",reader.line_num,"当前内容：",item)
        start_node = Node("person",name=item[0])
        end_node = Node("person",name=item[1])
        relation = Relationship(start_node,item[3],end_node)
        g.merge(start_node,"person","name")
        g.merge(end_node, "person", "name")
        g.merge(relation, "person", "name")